import React from 'react';
import { listImage } from 'services/image';
import Table from './Table';

export default class Image extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      imageList: [],
      loading: true,
    };
  }

  getImageList = () => {
    listImage().then((response) => {
      this.setState({ imageList: response, loading: false });
    });
  }

  componentDidMount() {
    this.getImageList();
  }

  render() {
    const { imageList, loading } = this.state;

    return (
      <Table
        dataSource={imageList}
        updateImage={this.getImageList}
        loading={loading}
      />
    );
  }
}
